package com.example.jiaowuchu.jiaowuSys.controller;

import com.example.jiaowuchu.jiaowuSys.pojo.yhpojo.User;
import com.example.jiaowuchu.jiaowuSys.service.UserService;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserServlet", value = "/UserServlet")
public class UserServlet extends HttpServlet {

    UserService userService=new UserService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action =request.getParameter("action");

        if (action.equals("update")){
            update(request,response);
        }else if (action.equals("login")){
            login(request,response);
        }



    }


    protected void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String old=request.getParameter("sno");
        String new1=request.getParameter("new1");
        String new2=request.getParameter("new2");
    }

    protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String yhm = request.getParameter("yhm");
        String pwd = request.getParameter("pwd");

        User user=new User(yhm,pwd,null,null,null);

        User yh=userService.select(user);
        HttpSession session=request.getSession();
        session.setAttribute("user",yh);
        String json=new Gson().toJson(yh);
        response.getWriter().print(json);
    }

    protected void register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
